package com.henghai.zhenxuan.ui.page.login;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ActivityUtils;
import com.henghai.zhenxuan.BR;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.kunminx.architecture.ui.page.BaseActivity;
import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.page.StateHolder;
import com.kunminx.architecture.ui.state.State;

/**
 * 协议详情页
 * 隐私政策
 * 用户协议
 */
public class AgreementActivity extends BaseActivity {

    private static String KEY = "agreementType";
    private AgreementStates mStates;
    private String agreementType;

    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(AgreementStates.class);
    }

    public static void gotoAgreement(String value) {
        Intent intent = new Intent(ActivityUtils.getTopActivity(), AgreementActivity.class);
        intent.putExtra(KEY, value);
        ActivityUtils.getTopActivity().startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        agreementType = getIntent().getStringExtra(KEY);
        mStates.agreementType.set(agreementType);
        if (agreementType.equals("服务协议")) {
            mStates.url.set("http://49.233.182.112:8899/yonghuxieyi.html");
        }
    }

    public class ListenerHandler implements OnTitleBarListener {
        @Override
        public void onLeftClick(TitleBar titleBar) {
            OnTitleBarListener.super.onLeftClick(titleBar);
            finish();
        }

        @Override
        public void onRightClick(TitleBar titleBar) {
            OnTitleBarListener.super.onRightClick(titleBar);
        }
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(com.henghai.zhenxuan.R.layout.activity_agreement, BR.vm, mStates).addBindingParam(BR.listener, new ListenerHandler());
    }

    public static class AgreementStates extends StateHolder {
        public final State<String> agreementType = new State<>("");
        public final State<String> url = new State<>("http://49.233.182.112:8899/yinsixieyi.html");
    }
}
